package com.ctsi.oppo.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.oppo.entity.BusinessOppoEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class OppoService   {
    private static final Logger logger= LoggerFactory.getLogger(OppoService.class);
    @Autowired
    private MybatisGenericDao dao;
    /**
     * 查询是否存在
     */
    public  int  selectOppoByName(String sjname){
        logger.debug("selectOppoByName {}",sjname);
        return (int) dao.queryForObject(BusinessOppoEntity.class.getName() + ".selectOppoByName", sjname);
    }

    /**
     * 插入
     */
    public int insertOppoNumber(BusinessOppoEntity businessOppoEntity){
        if(UtilValidate.isEmpty(businessOppoEntity.getId()))
            businessOppoEntity.setId(UUIDGenerator.getId());
        logger.debug("insert {}",businessOppoEntity);
        return 	dao.insert(businessOppoEntity);
    }

    /**
     * 更新
     */
    public int updateOppoByPKSelective(BusinessOppoEntity businessOppoEntity){
        logger.debug("updateOppoByPKSelective {}",businessOppoEntity);
        return dao.update(BusinessOppoEntity.class.getName()+".updateOppoByPKSelective", businessOppoEntity);
    }

    /**
     * 删除
     */
    public int deleteByPrimaryKey(String id){
        if(UtilValidate.isNotEmpty(id))
            return dao.delete(BusinessOppoEntity.class.getName()+".deleteByPrimaryKey", id);
        return 0;
    }

    /**
     * 多条件商机列表查询
     * @param param
     * @param start
     * @param pageSize
     * @return
     */
    public Page<BusinessOppoEntity> selectMulitCondition(Map<String,Object> param , int start , int pageSize){
        logger.debug("selectMulitCondition {}",param);
        if(pageSize<0||pageSize>2000)
            pageSize=Page.DEFAULT_PAGE_SIZE;
        if(start!=-1)
            return dao.queryPage(BusinessOppoEntity.class.getName()+".selectMulitCondition", param, start, pageSize);
        else{
            throw new RuntimeException("参数不正确 !!");
        }
    }

}
